import { MikroORM } from '@mikro-orm/core';
import { logger } from '@mikro-orm/nestjs';
import { SqlHighlighter } from '@mikro-orm/sql-highlighter';

import { EntityGenerator }  from '../../utils/EntityGenerator.js'

(async () => {
  const orm = await MikroORM.init({
    discovery: {
      // we need to disable validation for no entities
      warnWhenNoEntities: false,
    },
    contextName: 'zp',
    dbName: 'zp_apesk_net',
    user: 'zp_apesk_net',
    // dbName: 'typecho',
    // user: 'typecho',
    // dbName: 'leadshop',
    // user: 'leadshop',
    // dbName: 'zf_apesk_net', //ims_yzd_kp
    // user: 'zf_apesk_net',
    password: '88888888',
    type: 'mysql',
    host: '192.168.1.6',
    port: 3306,
    allowGlobalContext: true,
    highlighter: new SqlHighlighter(),
    entityGenerator: {
      entitySchema: true,
      bidirectionalRelations: true,
      identifiedReferences: true,
      esmImport: true,
    },
    //debug: true,
    //logger: logger.log.bind(logger),
  });


  const generator = new EntityGenerator(orm.em)//orm.getEntityGenerator();

  const options: any = {
    save: true,
    baseDir: process.cwd() + '/src/databases/entities',
    //baseDir: process.cwd() + '/src/databases/entities/ims_yzd_kp',

    //skipTables: ['book', 'author'],
    // skipColumns: {
    //   'public.user': ['email', 'middle_name'],
    // },
  };

  const dump = await generator.generate(options);
  console.log(dump);
  await orm.close(true);
})();
